<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>vue父子组件数据传递</title>
</head>
<body>
    <div id="app">
        <counter :count="1" @inc="handleIncrease"></counter>
        <counter :count="2" @inc="handleIncrease"></counter>
        <div>{{total}}</div>
    </div>
</body>
<script src="vue.js"></script>
<script>
    var counter = {
        props: ['count'],
        data: function() {
            return {
                number: this.count
            }
        },
        template: '<div @click="handleClick">{{number}}</div>',
        methods: {
            handleClick: function() {
                this.number+=2;
                this.$emit('inc', 2)
            }
        }
    }
    var app = new Vue({
        el: '#app',
        data: {
            content: 'hello world!',
            total: 3
        },
        components: {
            counter: counter,
        },
        methods: {
            handleIncrease: function(step) {
                this.total+=step;
            }
        }
    })
</script>
</html>
